package com.huawei.appgallery.forum.section.buoy.action;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import com.huawei.appgallery.assistantdock.base.externalaction.openviewaction.IOpenViewAction;
import com.huawei.appgallery.forum.option.api.IPublishPostActivityResult;
import com.huawei.appmarket.service.externalapi.view.ThirdApiActivity;
import com.huawei.secure.android.common.intent.SafeIntent;
import o.bqx;
import o.byd;
import o.cab.j;
import o.cbh;
import o.doo;
import o.dys.a;
import o.ezn;
import o.fho;
import o.fjf;
import o.fjo;
import o.fjq;

public class OpenPublishPostAction extends IOpenViewAction {
    private static final String ACTION_FORUM_PUBLISH_POST = "com.huawei.appmarket.intent.action.forum.publish.post";
    public static final String ACTION_OPEN_FORUM_PUBLISH_POST = "com.huawei.gamebox.ACTION_OPEN_FORUM_PUBLISH_POST";
    public static final String BUNDLE_DOMAINID = "DomainId";
    public static final String BUNDLE_LISTPOSTUNITDATA = "ListPostUnitData";
    public static final String BUNDLE_POSTID = "PostId";
    public static final String BUNDLE_POSTMODIFY = "PostModify";
    public static final String BUNDLE_POSTTITLE = "PostTitle";
    public static final String BUNDLE_SECTIONID = "SectionId";
    private static final int REQUEST_CODE = 9995;
    private static final String TAG = "OpenPublishPostAction";
    private static d publishPostCallBack;

    public interface d {
        void ˏ(byd o_byd);
    }

    public OpenPublishPostAction(a aVar, SafeIntent safeIntent) {
        super(aVar, safeIntent);
    }

    public void onAction() {
        if (this.callback instanceof Activity) {
            final Context context = (Activity) this.callback;
            if (doo.ˊ(context)) {
                ((cbh) fho.ˏ().ˋ("User").ॱ(cbh.class)).ˎ(context, 15).ˏ(new fjq<Boolean>(this) {
                    final /* synthetic */ OpenPublishPostAction ˊ;

                    public void onComplete(fjo<Boolean> o_fjo_java_lang_Boolean) {
                        if (!o_fjo_java_lang_Boolean.ˊ()) {
                            bqx.ˊ(OpenPublishPostAction.TAG, "task failed");
                            this.ˊ.callback.finish();
                        } else if (((Boolean) o_fjo_java_lang_Boolean.ॱ()).booleanValue()) {
                            Intent intent = new Intent("com.huawei.appmarket.intent.action.forum.publish.post");
                            intent.setClass(context, ThirdApiActivity.class);
                            intent.putExtra("DomainId", this.ˊ.intent.getStringExtra("DomainId"));
                            intent.putExtra("SectionId", this.ˊ.intent.getIntExtra("SectionId", -1));
                            intent.putExtra("PostId", this.ˊ.intent.getLongExtra("PostId", -1));
                            intent.putExtra("PostTitle", this.ˊ.intent.getStringExtra("PostTitle"));
                            intent.putExtra("ListPostUnitData", this.ˊ.intent.getSerializableExtra("ListPostUnitData"));
                            intent.putExtra("PostModify", this.ˊ.intent.getBooleanExtra("PostModify", false));
                            try {
                                ((Activity) this.ˊ.callback).startActivityForResult(intent, OpenPublishPostAction.REQUEST_CODE);
                            } catch (ActivityNotFoundException e) {
                                bqx.ˋ(OpenPublishPostAction.TAG, "ActivityNotFoundException :" + e.toString());
                            }
                        } else {
                            bqx.ˊ(OpenPublishPostAction.TAG, "check user task failed");
                            this.ˊ.callback.finish();
                        }
                    }
                });
                return;
            }
            ezn.ˊ().ˊ(context.getString(j.ˈ));
            this.callback.finish();
        }
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        if (i == REQUEST_CODE && i2 == -1) {
            dealWithData(intent);
        }
        clearCallback();
    }

    private void dealWithData(Intent intent) {
        notifyResult(((IPublishPostActivityResult) fjf.ˋ(intent).ॱ()).getPublishPostResult());
    }

    public static synchronized void registerCall(d dVar) {
        synchronized (OpenPublishPostAction.class) {
            publishPostCallBack = dVar;
        }
    }

    private static synchronized void notifyResult(byd o_byd) {
        synchronized (OpenPublishPostAction.class) {
            if (publishPostCallBack != null) {
                publishPostCallBack.ˏ(o_byd);
            }
        }
    }

    private static synchronized void clearCallback() {
        synchronized (OpenPublishPostAction.class) {
            publishPostCallBack = null;
        }
    }
}
